package com.cn.lp.ai.factory.domain.vector;

import com.cn.lp.ai.vector.AiVectorService;
import com.cn.lp.ai.vector.AiVectorServiceHandler;
import com.cn.lp.ai.vector.VectorType;
import com.cn.lp.common.utils.BlankAide;
import jakarta.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class LpAiVectorServiceHandler implements AiVectorServiceHandler {

    @Autowired
    private List<AiVectorService> aiVectorServiceList = new ArrayList<>();

    private Map<VectorType, AiVectorService> serviceMap = new HashMap<>();

    @PostConstruct
    protected void init() {
        if(BlankAide.isNotBlank(aiVectorServiceList)) {
            for (AiVectorService aiVectorService : aiVectorServiceList) {
                serviceMap.put(aiVectorService.getVectorType(), aiVectorService);
            }
        }
    }

    public Optional<AiVectorService> getByType(VectorType vectorType) {
        return Optional.ofNullable(serviceMap.get(vectorType));
    }

}
